package frame;

import constant.Probabilities;
import type.GameMode;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MainFrame extends JFrame {
    // 窗口尺寸
    private static final int width = 800;
    private static final int height = 620;
    // 窗口标题
    private static final String title = "贪吃蛇";

    public static GameMode GAME_MODE = GameMode.CLASSIC; // 默认为经典模式

    public static boolean soundCheckBox=true;//音效开关

    private boolean isDeveloper=false;//是否使用开发者设置
    private  int snakeInitLengthSlider; //蛇的初始长度
    private  int snakeInitSpeedSlider; //蛇的初始速度


    public MainFrame() {
        // 设置窗口标题
        setTitle(title);
        // 设置大小
        setSize(width, height);
        // 设置屏幕居中
        setLocationRelativeTo(null);
        // 不可改变大小
        setResizable(false);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//将界面关闭模式设置位关掉界面就停止虚拟机运行

        //播放背景音乐
        //String audioFilePath = "src/static/贪吃蛇大作战无限模式.wav";
        //MultimediaIO.playAudio(audioFilePath);

        // 窗口关闭提示
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                int option = JOptionPane.showConfirmDialog(MainFrame.this, "是否退出游戏", "确认退出", JOptionPane.YES_NO_OPTION);
                if (option == JOptionPane.YES_NO_OPTION) {
                    dispose();
                    System.exit(0);
                }
            }
        });
    }

    public boolean isSoundCheckBox() {
        return soundCheckBox;
    }

    public void setSoundCheckBox(boolean soundCheckBox) {
        this.soundCheckBox = soundCheckBox;
    }

    public boolean isIsDeveloper() {
        return isDeveloper;
    }

    public void setIsDeveloper(boolean isDeveloper) {
        this.isDeveloper = isDeveloper;
    }

    public int getSnakeInitLengthSlider() {
        return snakeInitLengthSlider;
    }

    public void setSnakeInitLengthSlider(int snakeInitLengthSlider) {
        this.snakeInitLengthSlider = snakeInitLengthSlider;
    }

    public int getSnakeInitSpeedSlider() {
        return snakeInitSpeedSlider;
    }

    public void setSnakeInitSpeedSlider(int snakeInitSpeedSlider) {
        this.snakeInitSpeedSlider = snakeInitSpeedSlider;
    }

    public int getNormalFoodProbabilitySlider() {
        return (int)(Probabilities.NORMAL_FOOD_PROB * 10);
    }

    public void setNormalFoodProbabilitySlider(int normalFoodProbabilitySlider) {
        Probabilities.NORMAL_FOOD_PROB = normalFoodProbabilitySlider / 10.0;
    }

    public int getSpeedUpFoodProbabilitySlider() {
        return (int)(Probabilities.SPEED_UP_FOOD_PROB * 10);
    }

    public void setSpeedUpFoodProbabilitySlider(int speedUpFoodProbabilitySlider) {
        Probabilities.SPEED_UP_FOOD_PROB = speedUpFoodProbabilitySlider/ 10.0;
    }

    public int getShieldFoodProbabilitySlider() {
        return (int)(Probabilities.SHIELD_FOOD_PROB * 10);
    }

    public void setShieldFoodProbabilitySlider(int shieldFoodProbabilitySlider) {
        Probabilities.SHIELD_FOOD_PROB = shieldFoodProbabilitySlider/ 10.0;
    }

    public int getThroughWallFoodProbabilitySlider() {
        return (int)(Probabilities.THROUGH_WALL_FOOD_PROB * 10);
    }

    public void setThroughWallFoodProbabilitySlider(int throughWallFoodProbabilitySlider) {
        Probabilities.THROUGH_WALL_FOOD_PROB = throughWallFoodProbabilitySlider/ 10.0;
    }
}
